$(function () {
    // 配置路径
    var pageUrl = config.urlAnaConfig.testPath;
    // 获取Cookie
    function getCookie(name){
        var strcookie = document.cookie;//获取cookie字符串
        var arrcookie = strcookie.split("; ");//分割
    //       console.log(arrcookie);
        //遍历匹配
        for ( var i = 0; i < arrcookie.length; i++) {
            var arr = arrcookie[i].split("=");
                if (arr[0] ==name){
                    return arr[1];
                }
        }
        return "";
    }
    var name = "tokenval";
    // tiken值
    var cookie_value = getCookie(name);
    console.log(cookie_value);

    // 初始化数据
    var data11 = "天猫";
    var data12 = "2018-双十一全球狂欢节";
    var data13 = "AW";
    var data14 = "INLINE";
    var data15 = "100";
    var data16 = "1.2";
    var data17 = "1.1";
    var data18 = "1.3";
    var data19 = "2";
    var data110 = "1";
    $.ajax({
            url: pageUrl+'/api/productforecast/getspus',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:data11,
                activity:data12,
                season:data13,
                line:data14,
                inv:data15,
                adjust_uv:data16,
                adjust_off:data17,
                adjust_inv:data18,
                cer:data19,
                division:'',
                heat:data110
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
                        var spusData = data.data.spus;
                        /*for in 循环*/
                         for(var i in spusData){
                             var arrtx1 = [];
                                arrtx1.push("<tr>");
                                arrtx1.push("<td>"+spusData[i].spu+"</td>");
                                arrtx1.push("<td>"+spusData[i].sum_pay_amount+"</td>");
                                arrtx1.push("<td>"+spusData[i].sum_pay_items+"</td>");
                                arrtx1.push("<td>"+spusData[i].off+"</td>");
                                arrtx1.push("<td>"+spusData[i].inv+"</td>");
                                arrtx1.push("<td>"+spusData[i].sum_uv+"</td>");
                                arrtx1.push("<td>"+spusData[i].avg_heat+"</td>");
                                arrtx1.push("<td>"+spusData[i].avg_cer+"</td>");
                                arrtx1.push("<td>"+"<input class='tzUv' type='number'" +"value="+spusData[i].adjust_uv+">"+"</td>");
                                arrtx1.push("<td>"+"<input class='tzZk' type='number'" +"value="+spusData[i].adjust_off+">"+"</td>");
                                arrtx1.push("<td>"+"<input class='tzBh' type='number'" +"value="+spusData[i].adjust_inv+">"+"</td>");
                                arrtx1.push("<td class='yucebeihuo'>"+spusData[i].invnum_forecast+"</td>");
                                arrtx1.push("<td class='yucexiaoliang'>"+spusData[i].payitems_forecast+"</td>");
                                arrtx1.push("<td class='yucezhekou'>"+spusData[i].discount_forecast+"</td>");
                                arrtx1.push("</tr>");
                                str0 = arrtx1.join('');
                                $(".table-date tbody").append(str0);
                         };
                            // table 调整备货
                            $(".tzBh").on("change",function () {
                                $(this).parent().next(".yucebeihuo").html($(this).val());
                            });
                            /*$(".tzUv").on("change",function () {
                                var xiaoliang = $(this).parents("tr").find("td").eq(2).html();
                                var xiaoluzhi = $(this).parents("tr").find("td").eq(7).html();
                                xiaoluzhi = Number(xiaoluzhi)+1;
                                var UVxishu = $(".details8").val()/100;
                                $(this).parent().nextAll(".yucexiaoliang").html(xiaoliang*xiaoluzhi/2*UVxishu);
                            });
                            $(".tzZk").on("change",function () {
                                var zhekou = $(this).parents("tr").find("td").eq(3).html();
                                var xiaoluzhi = $(this).parents("tr").find("td").eq(7).html();
                                xiaoluzhi = Number(xiaoluzhi)/9+0.9;
                                console.log()
                                var zhekouxishu = $(".details7").val()/100;
                                $(this).parent().nextAll(".yucexiaoliang").html(zhekou*xiaoluzhi*zhekouxishu);
                            });*/
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });


    // 下拉数据平台
    $.ajax({
        url: pageUrl+'/api/productforecast/getplatforms',
        type: 'POST',
        dataType: 'json',
        headers: {
            Authorization: 'Bearer '+cookie_value
        },
        success: function (data) {
            var msg = '';
            if (data) {
                if (data.code === 200) {
    //                  店铺名称
                    var details1 = data.data.platforms;
                    var details1F = $(".details1").next("ul");
                    /*for in 循环*/
                     for(var i in details1){
                         var text="<li>"+details1[i]+"</li>";
                         details1F.append(text);
                     };
                }
            }
        },
        error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

    });
       // 下拉数据活动
    $('.ulData1').on("click","li",function () {
        $(".details6").val("");
        $(".details2").val("");
        $(".details3").val("");
        $(".details6").attr("disabled",false).removeClass("border-hui");
        $(".details2").attr("disabled",true).addClass("border-hui");
        $(".details3").attr("disabled",true).addClass("border-hui");
        $(".details4").attr("disabled",true).addClass("border-hui");
        $(".details5").attr("disabled",true).addClass("border-hui");
        var details1D= $(".details1").val();
        console.log(details1D);
        $.ajax({
            url: pageUrl+'/api/productforecast/getactivitysbyplatform',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:details1D
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        $(".ulData6 li").remove();
                        var details6 = data.data.activitys;
                        console.log(details6);
                        var details6F = $(".ulData6");
                        /*for in 循环*/
                         for(var i in details6){
                             var text="<li>"+details6[i].name+"</li>";
                             details6F.append(text);
                         };
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
    });
    $('.ulData6').on("click","li",function(){
        $(".details2 option:gt(0)").remove();
        $(".details2").attr("disabled",false).removeClass("border-hui");
        $(".details3 option:gt(0)").remove();
        $(".details3").attr("disabled",false).removeClass("border-hui");
        $(".details4").attr("disabled",true).addClass("border-hui");
        $(".details5").attr("disabled",true).addClass("border-hui");
        var platformD = $('.details1').val();
        var seasonsD= $('.details6').val();
        console.log(seasonsD);
        // 季节
        $.ajax({
            url: pageUrl+'/api/productforecast/getseasons',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:platformD,
                activity:seasonsD,
                division:''
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        $(".ulData2 li").remove();
                        $(".details2").val("");
                        var details2 = data.data.seasons;
                        var details2F = $(".ulData2");
                        /*for in 循环*/
                         for(var i in details2){
                             var text="<li>"+details2[i]+"</li>";
                             details2F.append(text);
                         };
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
        // 商品属性1
        $.ajax({
            url: pageUrl+'/api/productforecast/getproductproperty1',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:platformD,
                activity:seasonsD
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        $(".ulData3 li").remove();
                        $(".details3").val("");
                        var details3 = data.data.divisions;
                        var details3F = $(".ulData3");
                        /*for in 循环*/
                         for(var i in details3){
                             var text="<li>"+details3[i]+"</li>";
                             details3F.append(text);
                         };
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
    });
    $('.ulData2').on("click","li",function(){
        $(".details4").attr("disabled",false).removeClass("border-hui");
        $(".details5").attr("disabled",false).removeClass("border-hui");
        var platformD= $('.details1').val();
        var seasonsD= $('.details2').val();
        var activityD = $('.details6').val();

        if (seasonsD == "全部"){
            var seasonsD1 = '';
        };
        console.log(seasonsD);
        // 商品属性2
        $.ajax({
            url: pageUrl+'/api/productforecast/getproductproperty2',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:platformD,
                activity:activityD,
                season:seasonsD1,
                division:''
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        $(".ulData4 li").remove();
                        var details4 = data.data.lines;
                        var details4F = $(".ulData4");
                        /*for in 循环*/
                         for(var i in details4){
                             var text="<li>"+details4[i]+"</li>";
                             details4F.append(text);
                         };
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
        // 商品属性3
        $.ajax({
            url: pageUrl+'/api/productforecast/getproductproperty3',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:platformD,
                activity:activityD,
                season:seasonsD1,
                line:'',
                division:''
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        $(".ulData5 li").remove();
                        var details5 = data.data.categorys;
                        var details5F = $(".ulData5");
                        /*for in 循环*/
                         for(var i in details5){
                             var text="<li>"+details5[i]+"</li>";
                             details5F.append(text);
                         };
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
    });




 /*   $('.details4').on("click","li",function(){
        $(".details5 option:gt(0)").remove();
        $(".details5").attr("disabled",false);
        var platformD= $('.details1').val();
        var seasonsD= $('.details2').val();
        var activityD = $('.details6').val();
        var lineD = $('.details4').val();
        console.log(lineD);
        // 商品属性3
        $.ajax({
            url: pageUrl+'/api/productforecast/getproductproperty3',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:platformD,
                activity:activityD,
                season:seasonsD,
                line:lineD,
                division:''
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        $(".ulData4 li").remove();
                        var details5 = data.data.categorys;
                        var details5F = $(".ulData4");
                        /!*for in 循环*!/
                         for(var i in details5){
                             var text="<li>"+details5[i]+"</li>";
                             details5F.append(text);
                         };
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
    });

    $('.details11').change(function(){
        $(".details22 option:gt(0)").remove();
        $(".details22").attr("disabled",false);
        var details1D= $(this).val();
        console.log(details1D);
        $.ajax({
            url: pageUrl+'/api/dailyactivity/getstorebyplatform',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:details1D
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
        //                  店铺名称
                        var details2 = data.data.stores;
                        console.log(details2);
                        var details2F = $(".details22");
                        var mydetails2 = details2;
                        /!*for in 循环*!/
                         for(var i in mydetails2){
                             var text="<option value='" + mydetails2[i] + "'>" + mydetails2[i] + " </option>";
                             details2F.append(text);
                         };

                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

        });
    });*/


    $(".application").on("click",function (e) {
        var event=e||event;
        event.preventDefault();
        var details1D = $(".details1").val();
        var details2D = $(".details2").val();
        var details3D = $(".details3").val();
        if (details3D == "全部"){
            details3D ='';
            $(".details2").val(0);
        }
        var details4D = $(".details4").val();
        if (details4D == "全部"){
            details4D ='';
            $(".details4").val(0);
        }
        // var details5D = $(".details5").val();
        var details6D = $(".details6").val();
        var data15 = $(".numberD1").val();
        var data19 = $(".numberD3").val();
        var data110 = $(".numberD2").val();
        var data16 = $(".details88").val()/100;
        var data17 = $(".details77").val()/100;
        var data18 = $(".details99").val()/100;
        if (details1D == 0 || details6D==0){
            alert("请选择完整选项");
            return false;
        };
        $.ajax({
            url: pageUrl+'/api/productforecast/getspus',
            type: 'POST',
            dataType: 'json',
            data:{
                platform:details1D,
                activity:details6D,
                division:details3D,
                season:details2D,
                line:details4D,
                inv:data15,
                adjust_uv:data16,
                adjust_off:data17,
                adjust_inv:data18,
                cer:data19,
                heat:data110
            },
            headers: {
                Authorization: 'Bearer '+cookie_value
            },
            success: function (data) {
                var msg = '';
                if (data) {
                    if (data.code === 200) {
                        var spusData = data.data.spus;
                        console.log(spusData);
                        /*for in 循环*/
                        $(".table-date tbody").empty();
                         for(var i in spusData){
                             var arrtx1 = [];
                                arrtx1.push("<tr>");
                                arrtx1.push("<td>"+spusData[i].spu+"</td>");
                                arrtx1.push("<td>"+spusData[i].sum_pay_amount+"</td>");
                                arrtx1.push("<td>"+spusData[i].sum_pay_items+"</td>");
                                arrtx1.push("<td>"+spusData[i].off+"</td>");
                                arrtx1.push("<td>"+spusData[i].inv+"</td>");
                                arrtx1.push("<td>"+spusData[i].sum_uv+"</td>");
                                arrtx1.push("<td>"+spusData[i].avg_heat+"</td>");
                                arrtx1.push("<td>"+spusData[i].avg_cer+"</td>");
                                arrtx1.push("<td>"+"<input class='tzUv' type='number'" +"value="+spusData[i].adjust_uv+">"+"</td>");
                                arrtx1.push("<td>"+"<input class='tzZk' type='number'" +"value="+spusData[i].adjust_off+">"+"</td>");
                                arrtx1.push("<td>"+"<input class='tzBh' type='number'" +"value="+spusData[i].adjust_inv+">"+"</td>");
                                arrtx1.push("<td class='yucebeihuo'>"+spusData[i].invnum_forecast+"</td>");
                                arrtx1.push("<td class='yucexiaoliang'>"+spusData[i].payitems_forecast+"</td>");
                                arrtx1.push("<td class='yucezhekou'>"+spusData[i].discount_forecast+"</td>");
                                arrtx1.push("</tr>");
                                str0 = arrtx1.join('');
                                $(".table-date tbody").append(str0);
                         };
                         // table 调整备货
                            $(".tzBh").on("change",function () {
                                $(this).parent().next(".yucebeihuo").html($(this).val());
                            });
                    }
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    $(".layer1 .content").html(errorTips);
                        $(".layer1").show();


                }

        });


    });

    // 保存
    $(".porm-btn").on("click",function () {
            $(this).attr("disabled","true");
            var details1D = $(".details1").val();
            var details2D = $(".details2").val();
            var details3D = $(".details3").val();
            if (details3D == "全部"){
                details3D =''
            }
            var details4D = $(".details4").val();
            if (details4D == "全部"){
                details4D =''
            }
            // var details5D = $(".details5").val();
            var details6D = $(".details6").find("option:selected").html();
            var data15 = $(".numberD1").val();
            var data19 = $(".numberD3").val();
            var data110 = $(".numberD2").val();
            var data16 = $(".details88").val()/100;
            var data17 = $(".details77").val()/100;
            var data18 = $(".details99").val()/100;
            if (details1D == 0 || details6D==0){
            alert("请选择完整选项");
            return false;
            };
            $(".layer2").show();
            // 提示弹框
            $(".layer2 .close1").on("click",function () {
                $(".layer2").hide();
            });
            $(this).parents(".layer2").hide();
            $.ajax({
                url: pageUrl+'/api/productforecast/getspus',
                type: 'POST',
                dataType: 'json',
                data:{
                    platform:details1D,
                    activity:details6D,
                    division:details3D,
                    season:details2D,
                    line:details4D,
                    inv:data15,
                    adjust_uv:data16,
                    adjust_off:data17,
                    adjust_inv:data18,
                    cer:data19,
                    heat:data110
                },
                headers: {
                    Authorization: 'Bearer '+cookie_value
                },
                success: function (data) {
                    var msg = '';
                    if (data) {
                        if (data.code === 200) {
                            setTimeout("$('.porm-btn').removeAttr('disabled')",2000);
                            // var aa = [];
                            var rows = document.getElementById("con1").rows.length;
                            //获得行数(包括thead)
                            var colums = document.getElementById("con1").rows[0].cells.length;
                            //获得列数
                            for (var i = 1; i < rows; i++) {
                                var spusData1 = data.data.spus;
                                var y = i-1;
                            // var spusData1 = new Object();
                                /*JsonData.spu = document.getElementById("con1").rows[i].cells[0].innerHTML;
                                spusData.sum_pay_amount = document.getElementById("con1").rows[i].cells[1].innerHTML;
                                spusData.sum_pay_items = document.getElementById("con1").rows[i].cells[2].innerHTML;
                                spusData.off = document.getElementById("con1").rows[i].cells[3].innerHTML;
                                spusData.inv = document.getElementById("con1").rows[i].cells[4].innerHTML;
                                spusData.sum_uv = document.getElementById("con1").rows[i].cells[5].innerHTML;
                                spusData.avg_heat = document.getElementById("con1").rows[i].cells[6].innerHTML;
                                spusData.avg_cer = document.getElementById("con1").rows[i].cells[7].innerHTML;*/
                                spusData1[y].adjust_uv = document.getElementById("con1").rows[i].cells[8].childNodes[0].value;
                                spusData1[y].adjust_off = document.getElementById("con1").rows[i].cells[9].childNodes[0].value;
                                spusData1[y].adjust_inv = document.getElementById("con1").rows[i].cells[10].childNodes[0].value;
                                spusData1[y].invnum_forecast = document.getElementById("con1").rows[i].cells[11].innerHTML;
                                spusData1[y].payitems_forecast = document.getElementById("con1").rows[i].cells[12].innerHTML;
                                spusData1[y].discount_forecast = document.getElementById("con1").rows[i].cells[13].innerHTML;
                            }
                            var obj = JSON.stringify(spusData1);
                            console.log(obj);
                            $(".qr-btn").on("click",function () {
                                $(this).parents(".layer2").hide();
                                console.log(obj);
                                var details1D = $(".details1").val();
                                var details2D = $(".details2").val();
                                var details3D = $(".details3").val();
                                if (details3D == "全部"){
                                    details3D =''
                                }
                                var details4D = $(".details4").val();
                                if (details4D == "全部"){
                                    details4D =''
                                }
                                // var details5D = $(".details5").val();
                                var details6D = $(".details6").find("option:selected").html();
                                var data15 = $(".numberD1").val();
                                var data19 = $(".numberD3").val();
                                var data110 = $(".numberD2").val();
                                var data16 = $(".details88").val()/100;
                                var data17 = $(".details77").val()/100;
                                var data18 = $(".details99").val()/100;
                                var data111 = $(".fanganName").val();
                                var data112 = $(".details6").val();
                                $.ajax({
                                    url: pageUrl+'/api/productforecast/savespus',
                                    type: 'POST',
                                    dataType: 'json',
                                    data:{
                                        platform:details1D,
                                        activity:details6D,
                                        division:details3D,
                                        season:details2D,
                                        line:details4D,
                                        inv:data15,
                                        adjust_uv:data16,
                                        adjust_off:data17,
                                        adjust_inv:data18,
                                        cer:data19,
                                        heat:data110,
                                        planName:data111,
                                        data:obj,
                                        rank:data112
                                    },
                                    headers: {
                                        Authorization: 'Bearer '+cookie_value
                                    },
                                    success: function (data) {
                                        var msg = '';
                                        if (data) {
                                            if (data.code === 200) {
                                                console.log("success")
                                            }
                                        }
                                    },
                                    error:  function (XMLHttpRequest, textStatus, errorThrown) {
                                            // msg
                                            var errorTips = XMLHttpRequest.responseJSON.msg;
                                            $(".layer1 .content").html(errorTips);
                                            $(".layer1").show();
                                            if(errorTips=='Token has expired'){
                                                $(".layer1 .content").html("令牌过期");
                                                $(".layer1").show();
                                                window.location.href="login.html";
                                            }


                                        }

                                });
                            });
                        }
                    }
                },
                error:  function (XMLHttpRequest, textStatus, errorThrown) {
                        // msg
                        setTimeout("$('.porm-btn').removeAttr('disabled')",2000);
                        var errorTips = XMLHttpRequest.responseJSON.msg;
                        $(".layer1 .content").html(errorTips);
                        $(".layer1").show();
                        if(errorTips=='Token has expired'){
                            $(".layer1 .content").html("令牌过期");
                            $(".layer1").show();
                            window.location.href="login.html";
                        }


                    }

        });




    });




    // 确定
    // 图形重置
    /*var pingjieIndex1 = 0;
    $(".application").on("click",function () {
        var details1Data = $(".details11").val();
        var detai2s1Data = $(".details22").val();
        if (details1Data == 0 || detai2s1Data==0){
            alert("请选择完整选项");
            return false;
        };
        // 拼接图形盒子1
        pingjieIndex1++;
        var tu1Id = "reportContainer";
        tu1Id = tu1Id + pingjieIndex1;
        console.log(tu1Id);
        var arrtx1 = [];
        arrtx1.push("<div class='tu11 no-border'" + "id=" +tu1Id +">");
        arrtx1.push("</div>");
        str1 = arrtx1.join('');
        $(".tu1").append(str1);
        // 删除其他元素
        $('.tu1'+' #'+tu1Id).siblings().remove();

        var url1 = "https://app.powerbi.cn/reportEmbed?reportId=0c221c7c-6529-4ec0-8191-8b73242d88fc&groupId=13e42e94-3404-46d8-b605-228c35984df3";
        url1 = url1+"&filter=platform_table/code eq"+" '"+details1Data+"' "+"and store_table/code eq "+"'"+detai2s1Data+"'";
        $.ajax({
            url: pageUrl+'/api/common/getaccesstoken',
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                var msg = '';
                if (data) {
                    var accessToken = data.data.accessToken.value;
                    rchd(accessToken,url1);
                }
            },
            error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }
        });
    });*/
        // 图表
/*    $.ajax({
        url: pageUrl+'/api/common/getaccesstoken',
        type: 'POST',
        dataType: 'json',
        success: function (data) {
            var msg = '';
            if (data) {
                var accessToken = data.data.accessToken.value;
                var myUrl = "https://app.powerbi.cn/reportEmbed?reportId=845b7808-42e6-473b-9c0c-565edd70ac3f&groupId=13e42e94-3404-46d8-b605-228c35984df3";
                 rchd(accessToken,myUrl);
            }
        },
        error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    if (errorTips=='Division by zero'){
                        $(".layer1 .content").html("数据错误");
                        $(".layer1").show();
                        console.log(errorTips);
                    } else if(errorTips=='Token has expired'){
                        $(".layer1 .content").html("令牌过期");
                        $(".layer1").show();
                        window.location.href="login.html";
                    }


                }

    });

    function rchd(accessToken,myUrl) {
        // Read embed application token from Model
        var accessToken = accessToken;
        // Read embed URL from Model
        var embedUrl = myUrl;
        console.log(accessToken);
        console.log(embedUrl);
        // Read report Id from Model
        var embedReportId = "845b7808-42e6-473b-9c0c-565edd70ac3f";
        // Get models. models contains enums that can be used.
        var models = window['powerbi-client'].models;
        // Embed configuration used to describe the what and how to embed.
        // This object is used when calling powerbi.embed.
        // This also includes settings and options such as filters.
        // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
        var config = {
            type: 'report',
            // tokenType: models.TokenType.Embed,
            accessToken: accessToken,
            embedUrl: embedUrl,
            id: embedReportId,
            viewMode: models.ViewMode.View,
            // filters: filter,
            permissions: models.Permissions.All ,
            settings: {
                filterPaneEnabled: false,
                navContentPaneEnabled: false
            }
        };
        // Get a reference to the embedded report HTML element
        var tu11 = $('.tu11')[0];
        if ("" != "") {
            $("#RLS").prop('checked', true);
            $("#RLSdiv").show();
        }
        else
        {
            $("#RLS").prop('checked', false);
            $("#RLSdiv").hide();
        }
        if ("False" == "True") {
            $("#noRLSdiv").hide();
            $("#RLS").removeAttr("disabled");
            $("#RLS").change(function () {
                if ($(this).is(":checked")) {
                    $("#RLSdiv").show(300);
                } else {
                    $("#RLSdiv").hide(200);
                }
            });
        }
        else
        {
            $("#noRLSdiv").show();
        }
        var report = powerbi.embed(tu11, config);
    };*/
});